package com.example.myapplication.utils

import com.google.gson.TypeAdapter
import com.google.gson.stream.JsonReader
import com.google.gson.stream.JsonWriter
import android.net.Uri

class UriTypeAdapter : TypeAdapter<Uri>() {
    override fun write(out: JsonWriter, value: Uri?) {
        out.value(value?.toString()) // 序列化：Uri -> String
    }

    override fun read(reader: JsonReader): Uri? {
        return reader.nextString()?.let { Uri.parse(it) } // 反序列化：String -> Uri
    }
}